package demo1;


class OuterClass {


    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    //静态内部类
    static class InnerClass{
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;

        public void func() {
            System.out.println("static->InnerClass::func()");
            //静态内部类中 不能直接访问外部类的非静态成员
            //System.out.println(data1);//不能被访问到，

            //间接访问  给一个外部类的引用
            OuterClass outerClass = new OuterClass();
            System.out.println(outerClass.data2);

            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }

    public void test() {
        InnerClass innerClass = new InnerClass();
        System.out.println(data1);
        System.out.println(data2);
        System.out.println(data3);
        System.out.println(innerClass.data4);
        //外部类 可以访问静态类中的所有成员，包括私有的
        System.out.println(innerClass.data5);
        System.out.println(innerClass.data6);


    }

}
public class Test {
    public static void main(String[] args) {
        //如何实例化静态类对象
        OuterClass.InnerClass innerClass = new OuterClass.InnerClass();
        innerClass.func();
    }
}
